package huaweiod.first;

import java.util.*;

/**
 * 华为OD机试真题 Java 实现【最小调整顺序次数】【2022.11 Q4 新题】
 * 这题有点蠢
 */
public class A_2023_09_DoubleQueueOperate {

    public static void main(String[] args) {
        // 处理输入
        Scanner in = new Scanner(System.in);
        List<String> operaions = new ArrayList<>();
        while(in.hasNextLine()){
            operaions.add(in.nextLine());
        }
        int n = Integer.parseInt(operaions.get(0));

        int ans = 0;
        int queueSize = 0;
        boolean flag = true;
        for (int i = 1; i < operaions.size(); i++) {
            String op = operaions.get(i);
            if(op.contains("head")) {
                if(queueSize > 0){
                    flag = false;
                }
                queueSize++;
            }
            if(op.contains("tail")) {
                queueSize++;
            }
            if(op.contains("remove")) {
                if(!flag) {
                    ans++;
                }
            }
        }
        System.out.println(ans);
    }
}
